<pre>
<?php

//error_reporting(E_ALL);
require_once 'Excel/reader.php';

if(isset($_REQUEST['File'])) $fname = $_REQUEST['File'];
######################################## 2 per test
else $fname = '../../contacts/dbdef/ContactFieldMap';

$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read("$fname.xls");

$array = "<?php \n";
$array.= "global \$dbdef; \n" ;

//ciclo sulle righe
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
	
	//ciclo sulle colonne
	for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
		
		
		//salvo in array i titoli di colonna
		if($i==1) {
			$fields[$j] = $data->sheets[0]['cells'][$i][$j];
			//recuper indice del campo TableName e FieldName
			if($fields[$j]=='TableName') $idxTableName = $j;
			else if($fields[$j]=='FieldName') $idxFieldName = $j;
			
		}	else{
			
			//sulla prima colonna recupero i dati relativi a FiledName e TableName
			if($j==1){
				$tableName = $data->sheets[0]['cells'][$i][$idxTableName];
				$fieldName = $data->sheets[0]['cells'][$i][$idxFieldName];
			}
			
			$field = $fields[$j] ;
			$value = $data->sheets[0]['cells'][$i][$j];
			
			
			$tmp = "\$dbdef['$tableName'] ['$fieldName'] ['$field']  = \"$value\"; \n" ;
			$array.=$tmp;
			echo $tmp;
		} 
		
		
	}
	
	$array.="\n";
	echo "\n";
	
}

$array.= "?>";
$fPath = "${fname}.inc";
$hf=fopen($fPath,'w');
fwrite($hf,$array);	
fclose($hf);


?>

</pre>